package com.shycloud.mido.member.service.impl;

import com.shycloud.mido.common.core.util.R;
import com.shycloud.mido.member.api.entity.MultiAssist;
import com.shycloud.mido.member.api.vo.MultiAssistRecordVO;
import com.shycloud.mido.member.mapper.MultiAssistMapper;
import com.shycloud.mido.member.pattern.ISubjectStrategy;
import com.shycloud.mido.member.pattern.SubjectBuilder;
import com.shycloud.mido.member.pattern.SubjectDirector;
import com.shycloud.mido.member.pattern.SubjectPayload;
import com.shycloud.mido.member.pattern.SubjectStrategyFactory;
import com.shycloud.mido.member.service.MultiAssistService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author baiqiang
 * @since 2021-07-12
 */
@Service
public class MultiAssistServiceImpl extends ServiceImpl<MultiAssistMapper, MultiAssist>
		implements MultiAssistService {

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void assign(MultiAssistRecordVO vo) throws Exception {
		// 构建载体
		SubjectPayload payload = new SubjectPayload(vo);
		// 创建策略
		ISubjectStrategy subjectStrategy = new SubjectStrategyFactory().configStrategy(SubjectDirector.strategyMap(() -> {
			return new SubjectBuilder().buildOptAssign().buildOrgAssign().buildTeacherAssign().build();
		})).getSubjectStrategy(payload.acquireSubject());
		// 策略执行
		subjectStrategy.execute(payload);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void opening(MultiAssistRecordVO vo) throws Exception {
		// 构建载体
		SubjectPayload payload = new SubjectPayload(vo);
		// 创建策略
		ISubjectStrategy subjectStrategy = new SubjectStrategyFactory().configStrategy(SubjectDirector.strategyMap(() -> {
			return new SubjectBuilder().buildStudentOpening().build();
		})).getSubjectStrategy(payload.acquireSubject());
		// 策略执行
		subjectStrategy.execute(payload);

	}
}
